#!/bin/bash

#	First argument is the path to dionaea file
#	Second argument is temporary database index

DB_USER="root"
DB_PASS="rootpass"

#	Check if arguments are found

if [ $# != 2 ]; then
	echo "Not the right amount of arguments"
	exit
fi

#	Check if argument is a file

if [ -f $1 ]; then

#	Create temporary database and set privileges

	sqlite3 $1 .dump > dionaea_sqlite_$2.sql

	./convert.pl dionaea_sqlite_$2.sql > dionaea_mysql_$2.sql

	mysql -u $DB_USER --password=$DB_PASS -e "DROP DATABASE IF EXISTS honeyviz_dionaea_$2; CREATE DATABASE honeyviz_dionaea_$2; GRANT ALL ON honeyviz_dionaea_$2.* TO 'uploader';"

	mysql -u $DB_USER --password=$DB_PASS honeyviz_dionaea_$2 < dionaea_mysql_$2.sql

	mysql -u $DB_USER --password=$DB_PASS honeyviz_dionaea_$2 < create_submission.sql

	mysql -u $DB_USER --password=$DB_PASS honeyviz_dionaea_$2 < create_dionaea.sql

	mysql -u $DB_USER --password=$DB_PASS honeyviz_dionaea_$2 < load_dionaea.sql

	rm dionaea_sqlite_$2.sql

	rm dionaea_mysql_$2.sql

	exit
fi

echo "No file found"

